package com.example.contactlist;

import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Contact implements Serializable{

	private long id;
	private String name;
	private String adr;
	private String tel;
	private String mail;
	private String kana;
	private String img;
	private String alertName="名前を入力してください";
	private String alertMail="アドレスを入力してください";
	private String alertTel="電話番号を入力してください";

	public String getAlertMail() {
		return alertMail;
	}
	public String getAlertTel() {
		return alertTel;
	}
	public String getAlertName() {
		return alertName;
	}
	public long getId() {
		return id;
	}
	public String getName() {
		return name;
	}
	public String getAdr() {
		return adr;
	}
	public String getTel() {
		return tel;
	}
	public String getMail() {
		return mail;
	}
	public String getKana() {
		return kana;
	}
	public String getImg() {
		return img;
	}
	public void setId(long id) {
		this.id = id;
	}
	public void setName(String name) {
		this.name = name;
		if (name==null || name.length()==0) {
			alertName="名前が未入力です";
		}
		else {
			alertName=null;
		}

	}
	public void setAdr(String adr) {
		this.adr = adr;
	}
	public void setTel(String tel) {
		this.tel = tel;
		if (tel==null || tel.length()==0) {
			alertTel="電話番号が未入力です";
		}
		else {
			Pattern p1 = Pattern.compile("^0\\d-\\d{4}-\\d{4}$|"
					+ "^0\\d{2}-\\d{3,4}-\\d{4}$|"
					+ "^0\\d{2}-\\d{3,4}-\\d{4}$|"
					+ "^0\\d{3}-\\d{2}-\\d{4}$|"
					+ "^0\\d{4}-\\d-\\d{4}$|"
					+ "^0\\d{3}-\\d{3}-\\d{3}$|"
					+ "^0\\d{9,10}$");
					Matcher m = p1.matcher(tel);
			if(m.find()){
				alertTel=null;
			}
			else {
				alertTel="正しく入力してください";
			}
		}
	}
	public void setMail(String mail) {
		this.mail = mail;
		if (mail==null || mail.length()==0) {
			alertMail="メールアドレスが未入力です";
		}
		else {
			Pattern p2 = Pattern.compile("[a-zA-Z][a-zA-Z0-9]*@[a-zA-Z.]*[a-zA-Z]$");
			Matcher m = p2.matcher(mail);
			if(m.find()){
				alertMail=null;
			}
			else {
				alertMail="正しく入力してください";
			}
		}
	}
	public void setKana(String kana) {
		this.kana = kana;
	}
	public void setImg(String img) {
		this.img = img;
	}
	public boolean inputCheck(){
		return (alertName==null && alertTel==null && alertMail==null);
	}
}

